#include <iostream>
#include <vector>
using namespace std;

int main() {
	
	int n;
	cin>>n;
	vector<int> vecPrices(n+1);
	for(int i=1;i<=n;++i){
		cin>>vecPrices[i];
	}
	int nSale=0,nBuy=-vecPrices[1];
	for(int i=2;i<=n;++i){
		int nTmpSale=max(nSale,nBuy+vecPrices[i]);
		int nTmpBuy=max(nBuy,nSale-vecPrices[i]);
		nSale=nTmpSale;
		nBuy=nTmpBuy;
	}
	cout<<max(nSale,nBuy)<<endl;
	
	return 0;
}
